package org.huntaway.kindergarten.service.daily;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.huntaway.kindergarten.manager.ClassInfoMng;
import org.huntaway.kindergarten.manager.GenearchMng;
import org.huntaway.kindergarten.manager.StudentMng;
import org.huntaway.kindergarten.manager.TeacherMng;
import org.huntaway.kindergarten.po.Student;
import org.huntaway.kindergarten.service.KindProcessor;
import org.huntaway.kindergarten.util.GlobalCon;

public class StudentService extends KindProcessor<Student> {

	public StudentService() {
		super();
		baseMng = (StudentMng) sm.getMng(GlobalCon.STUDENT);
	}

	@Override
	public Student getObj() {
		return new Student();
	}

	public ActionForward query(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		item = (Student) setValue(request, getObj());
		ActionForward serBean = super.query(mapping, form, request, response);
		setPageValue(request);
		return serBean;
	}

	public ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		item = (Student) setValue(request, getObj());
		ActionForward serBean = super.list(mapping, form, request, response);
		setPageValue(request);
		return serBean;
	}

	public ActionForward addBegin(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward serBean = super
				.addBegin(mapping, form, request, response);
		setPageValue(request);
		return serBean;
	}

	private void setPageValue(HttpServletRequest request) {
		request.setAttribute("classLst",
				((ClassInfoMng) sm.getMng(GlobalCon.CLASS_INFO)).getClassInfo());
		request.setAttribute("genearchLst",
				((GenearchMng) sm.getMng(GlobalCon.GENEARCH)).getGenearch());
		request.setAttribute("teacherLst",
				((TeacherMng) sm.getMng(GlobalCon.TEACHER)).getTeacher());
	}

	public ActionForward addProcess(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward serBean = super.addProcess(mapping, form, request,
				response);
		return serBean;
	}

	public ActionForward editBegin(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ActionForward serBean = super.editBegin(mapping, form, request,
				response);
		setPageValue(request);
		return serBean;
	}
}
